<?php
/** 
 * @package AMFramework
 * @subpackage Core_MVC
 * @author Marcu Alexandru
 * @version 1.0 $Build 305b  
 */
defined('_INDEX') or die('Restricted');

class Amfw_Model extends Amfw_Object
{

	 /** Prelucreaza numele tabelului si numele clasei model, pentru a formula o cerere
	 * corecta catre Factory (din numele modelului se verifica daca apartine sau nu de un 
	 * modul)
	 * 
	 * @param String $name	Numele tabelului cerut
	 */
	protected function &getTable( $name ) {
		if(is_subclass_of($this,'Amfw_Model')) 
		{
			$info = $this->mirror($this);

			// Model name tokens
			$tokens = explode('_',$info['name']);
			if($tokens[0] == $info['prefix'] && $tokens[1] == 'Model')
			{
				// Overwrite it
				$tokens[1] 	= 'Table';

				// Numele table-ului este scris in ultimul token
				$size 		= count($tokens);
				$tokens[$size-1] = $name;
				
				return Amfw_Factory::getTable($tokens);
			}
			else 
			{
				trigger_error(	"The model from which <u>table: $name</u> is called <b>does not 
								match the Amfw naming conventions</b>. Returned null",E_USER_WARNING); 
				return null;
			}
		}
		return null;
	}
	
}